home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / applic / ntp / acts.arc / WAIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-15  |  1.7 KB  |  83 lines

  1. void wait()
  2. {
  3. /*
  4.         this subroutine delays by 1 second each time
  5.         it is called.  the delay is only approximate and
  6.         is in fact 18 ticks of the clock for an IBMPC.  for
  7.     a SUN version, the program waits until the low part
  8.     of the time wraps around to the same value again
  9. */
  10. #include "nbstime.h"
  11. #include <stdio.h>
  12. #ifdef IBMPC
  13. #include <dos.h>
  14. #if defined(MSC)
  15. struct dostime_t time;
  16. #endif
  17. #endif
  18. #ifdef SUN
  19. #include <sys/time.h>
  20. struct timeval tvv,*tp;
  21. long int old,dly;
  22. #endif
  23. int j;
  24. int k,kk;
  25. /*
  26.         get current hundredths of time for IBMPC or current
  27.     microseconds for sun
  28. */
  29. #ifdef IBMPC
  30. #if defined(MSC)
  31.     _dos_gettime(&time);
  32.     k=time.hsecond;
  33. #else
  34.         _AH=0x2c;
  35.         geninterrupt(0x21);
  36.         k=_DL;
  37. #endif
  38. #endif
  39. #ifdef SUN
  40.     tp= &tvv;
  41.     gettimeofday(tp,0);
  42.     old=tp->tv_usec;
  43. #endif
  44. #ifdef IBMPC
  45. /*
  46.     for IBMPC version, wait until tick changes 18 times --
  47.     that is approximately 1 second, although the change
  48.     of the first tick is likely to happen too soon and
  49.     the number of ticks/sec is slightly more than 18 --
  50.     both of these will cause the delay to be a bit too
  51.     short.
  52. */
  53.         for(j=0; j<18; j++)
  54.         {
  55.         do
  56.         {
  57. #if defined(MSC)
  58.     _dos_gettime(&time);
  59.     kk=time.hsecond;
  60. #else
  61.         _AH=0x2c;
  62.         geninterrupt(0x21);
  63.         kk=_DL;
  64. #endif
  65.         } while (kk == k);
  66.         k=kk;
  67.         }
  68. #endif
  69. #ifdef SUN
  70. /*
  71.     for SUN version, wait until new value of microseconds is
  72.     just slightly less than old value.
  73. */
  74.     do
  75.     {
  76.     gettimeofday(tp,0);
  77.     dly=tp->tv_usec - old;
  78.     if(dly < 0) dly += 1000000;
  79.     for(k=0; k<20; k++)  ;   /* wait a bit */
  80.     } while (dly <= 970000);
  81. #endif
  82. }
  83.